package Annuaire.impl;

import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.PortableServer.*;

public class Server {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			// create and initialize the ORB
			ORB orb = ORB.init(args, null);

			// get reference to rootpoa & activate the POAManager
			POA rootpoa = POAHelper.narrow(orb
					.resolve_initial_references("RootPOA"));
			rootpoa.the_POAManager().activate();

			ServiceImpl service = new ServiceImpl();

			// get object reference from the servant
			org.omg.CORBA.Object ref = rootpoa.servant_to_reference(service);
			
			//Hello href = HelloHelper.narrow(ref);
			// get the root naming context ; NameService
			org.omg.CORBA.Object objRef =
					orb.resolve_initial_references("NameService");
			NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
			
			// bind the Object Reference in Naming
			String name = "Annuaire";
			NameComponent path[] = ncRef.to_name(name);
			ncRef.rebind(path, ref);
			System.out.println("HelloServer ready and waiting ...");
			
			// wait for invocations from clients
			orb.run();
		} catch (Exception e) {
			System.err.println("ERROR: " + e);
			e.printStackTrace();
		} finally {
		}
	}

}
